﻿using Topshelf;
using System;

namespace Quartz.Server
{
    /// <summary>
    /// The server's main entry point.
    /// </summary>
    public static class Program
    {
        /// <summary>
        /// Main.
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            HostFactory.Run(x =>
            {
                x.Service<IQuartzServer>(s =>
                {
                    s.ConstructUsing(name =>
                    {
                        QuartzServer server = new QuartzServer();
                        server.Initialize();
                        Console.WriteLine("service start");
                        return server;
                    });
                    s.WhenStarted(server => server.Start());
                    s.WhenStopped(server => server.Stop());
                });
                x.RunAsLocalSystem();

                x.SetDescription(Configuration.ServiceDescription);
                x.SetDisplayName(Configuration.ServiceDisplayName);
                x.SetServiceName(Configuration.ServiceName);
            });
        }

    }
}
